'use strict'

class newAdmin {
    constructor() {
        this.param = '/'
    }

    async post(c) {
        var newAdmin = JSON.parse(c.body);
        console.log(newAdmin);
        //根据name获取文件对象。
        try {
            var count = await c.service.psql.query(`select MAX(admin_id) from admin`);
            count = count.rows[0].max;
            count++;
            console.log(count);
            await c.service.psql.query(`insert into admin (admin_name,admin_passwd,headshop,admin_id) values('${newAdmin.newName}','${newAdmin.newPass}','head.jpg',${count})`)
            return c.send('success');

        } catch (err) {
            console.log(err);
            return c.status(500).send('filed');
        }
    }

}

module.exports = newAdmin
